from com.arcfox.base.base_spider import BaseSpider
from com.arcfox.middleware.async_redis_middleware import open_redis
from com.arcfox.util import constant

'''
    聚志愿爬虫基类
'''


class JZYBaseSpider(BaseSpider):

    def __init__(self):
        super().__init__()
        self.data_version = None
        self.host = "http://www.juzhiyuan.com"
        self.TASK_KEY_SCHOOL_LIST = "task_school_list_jzy"
        self.TASK_SCHOOL_MAJOR_LIST_JZY = "task_school_major_list_jzy"
        self.TASK_KEY_SCHOOL_MAJOR_LIST = "task_school_major_list_jzy"
        self.TASK_KEY_MAJOR_SCORE = "task_major_score_jzy"
        self.TASK_MAJOR_LIST_JZY = "task_major_list_jzy"
        self.TASK_SEGMENT_LIST_JZY = "task_segment_list_jzy"
        self.TASK_SCHOOL_ZSJH_LIST_JZY = "task_school_zsjh_list_jzy"
        self.TASK_SCHOOL_PROVINCE_LIST_JZY = "task_school_province_list_jzy"

    @open_redis
    async def init_data_version(self, client):
        value = await client.get(constant.CONFIG_KEY_DATA_VERSION)
        if value:
            self.data_version = value.decode()

    def get_province_map(self):
        return {
            "安徽": 34, "北京": 11, "重庆": 50, "福建": 35, "甘肃": 62, "广东": 44, "广西": 45, "贵州": 52,
            "海南": 46, "河北": 13, "河南": 41, "黑龙江": 23, "湖北": 42, "湖南": 43, "江西": 36, "吉林": 22,
            "江苏": 32, "辽宁": 21, "内蒙古": 15, "宁夏": 64, "青海": 63, "山东": 37, "山西": 14, "陕西": 61,
            "上海": 31, "四川": 51, "天津": 12, "新疆": 65, "云南": 53, "浙江": 33
        }

    def get_province_map_reverse(self):
        return {
            34: "安徽", 11: "北京", 50: "重庆", 35: "福建", 62: "甘肃", 44: "广东", 45: "广西", 52: "贵州", 46: "海南", 13: "河北",
            41: "河南", 23: "黑龙江", 42: "湖北", 43: "湖南", 36: "江西", 22: "吉林", 32: "江苏", 21: "辽宁", 15: "内蒙古", 64: "宁夏",
            63: "青海", 37: "山东", 14: "山西", 61: "陕西", 31: "上海", 51: "四川", 12: "天津", 65: "新疆", 53: "云南", 33: "浙江"
        }
